﻿@{
    Layout = null;

    string session = (ViewBag.Project.ViewEngine == ViewEngine.WebForms ? (Page.WebFormsSessionReference ?? "slickUpload.UploadSession") : (ViewBag.Sample.HasModel ? "Model.UploadSession" : "Model"));
}
@if (ViewBag.Project.ViewEngine == ViewEngine.Mvc || ViewBag.Project.ViewEngine == ViewEngine.Razor)
{
    string modelReference;
    
    if (ViewBag.Sample.HasModel)
    {
        modelReference = ViewBag.Project.Name + ".Models." + ViewBag.Sample.Path + "Model";
    }
    else
    {
        modelReference = "Krystalware.SlickUpload.UploadSession";
    }    

@RenderPage("~/Views/Samples/Generic/PageDeclaration.cshtml", new {
    Title = ViewBag.Sample.Name,
    RegisterSlickUpload = false,
    Model = modelReference
})
@SampleHelper.BeginSection("content", true)
}
            <h2>Upload Result</h2>
             @SampleHelper.RenderCode(SampleHelper.VaryByLanguage("if (" + session + " != null) {", "If Not " + session + " Is Nothing Then"))
                <p>Result: @SampleHelper.RenderStatement("" + session + ".State.ToString()")</p>
                @SampleHelper.RenderCode(SampleHelper.VaryByLanguage("if (" + session + ".State != UploadState.Error) {", "If " + session + ".State <> UploadState.Error Then"), true)
                <p>Files Uploaded: @SampleHelper.RenderStatement("" + session + ".UploadedFiles.Count.ToString()")</p>
                <table class="results" width="99%" cellpadding="4" cellspacing="0">
                    <thead>
                        <tr>
                            <th align="left">Server Location</th>
                            <th align="left">Mime Type</th>
                            @RenderSection("new_column_header", false)
                            <th align="left">Length (bytes)</th>
                        </tr>
                    </thead>
                    <tbody>
                        @if (ViewBag.Project.ViewEngine == ViewEngine.WebForms)
                        {
                        <asp:Repeater ID="resultsRepeater" runat="server">
                            <ItemTemplate>
                                <tr>
                                    <td><%#@SampleHelper.VaryByLanguage("((UploadedFile)Container.DataItem).ServerLocation.Replace(\"\\\\\", \"\\\\<wbr />\")", "DirectCast(Container.DataItem, UploadedFile).ServerLocation.Replace(\"\\\", \"\\<wbr />\")") %></td>
                                    <td><%#@SampleHelper.VaryByLanguage("((UploadedFile)Container.DataItem).ContentType", "DirectCast(Container.DataItem, UploadedFile).ContentType") %></td>
                                    @RenderSection("new_column", false)
                                    <td><%#@SampleHelper.VaryByLanguage("((UploadedFile)Container.DataItem).ContentLength", "DirectCast(Container.DataItem, UploadedFile).ContentLength") %></td>
                                </tr>
                            </ItemTemplate>
                        </asp:Repeater>
                        }
                        else
                        {
                        @SampleHelper.RenderCode(SampleHelper.VaryByLanguage("foreach (UploadedFile file in " + session + ".UploadedFiles) {", "For Each file As UploadedFile In " + session + ".UploadedFiles"))
                        <tr>
                            <td>
                                @SampleHelper.RenderStatement(SampleHelper.VaryByLanguage("file.ServerLocation.Replace(\"\\\\\", \"\\\\<wbr />\")", "file.ServerLocation.Replace(\"\\\", \"\\<wbr />\")").ToString(), true)
                            </td>
                            <td>
                                @SampleHelper.RenderStatement("file.ContentType")
                            </td>
                            @RenderSection("new_column", false)
                            <td>
                                @SampleHelper.RenderStatement("file.ContentLength")
                            </td>
                        </tr>
                        @SampleHelper.RenderCode(SampleHelper.VaryByLanguage("}", "Next file"), true)
                        }
                        @SampleHelper.RenderCode(SampleHelper.VaryByLanguage("if (" + session + ".UploadedFiles.Count == 0) {", "If " + session + ".UploadedFiles.Count = 0 Then"))
                        <tr class="nodata">
                            <td colspan="3">No files recieved.</td>
                        </tr>
                        @SampleHelper.RenderCode(SampleHelper.VaryByLanguage("}", "End If"), true)
                    </tbody>
                </table>
                @SampleHelper.RenderCode(SampleHelper.VaryByLanguage("} else {", "Else"), true)
                <p>Error Summary: @SampleHelper.RenderStatement("" + session + ".ErrorSummary")</p>
                @SampleHelper.RenderCode(SampleHelper.VaryByLanguage("}", "End If"), true)
            @SampleHelper.RenderCode(SampleHelper.VaryByLanguage("} else {", "Else"), true)
            <p>No upload recieved.</p>
            @SampleHelper.RenderCode(SampleHelper.VaryByLanguage("}", "End If"), true)
            <p>
                @if (!IsSectionDefined("newupload"))
                {
                @SampleHelper.RenderButton("newUploadButton", "button", null, "href=\"" + SampleHelper.RenderStatement("Url.Action(\"Index\")") + "\"", null, @<span><b class="icon newupload"></b> New Upload</span>)                    
                }
                else
                {
                    @RenderSection("newupload")
                }
                <div style="clear:both"></div>
            </p>
@if (ViewBag.Project.ViewEngine == ViewEngine.Mvc || ViewBag.Project.ViewEngine == ViewEngine.Razor)
{
@SampleHelper.EndSection(true)
@SampleHelper.BeginSection("description")
    @Html.Raw(ViewBag.Sample.Description)
@SampleHelper.EndSection()}
                          
@RenderBody()